<?php
/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-6-8
 * Time: 0:10
 * @description:
 * @Author: yfl
 * @QQ 554665488
 */
/**
 * Sql 堆结构先进先出
 */

$heap= new SplMinHeap();

$heap->insert("data1\n");
$heap->insert("data2\n");

echo $heap->extract();
echo $heap->extract();
//最小堆
class MinHeap extends SplHeap
{
    protected function compare($a, $b)
    {
        return $b - $a;
    }
}
//最大堆
class MaxHeap extends SplHeap
{
    protected function compare($a, $b)
    {
        return $a - $b;
    }
}
$list = new MaxHeap;
$list->insert(56);
$list->insert(22);
$list->insert(35);
$list->insert(11);
$list->insert(88);
$list->insert(36);
$list->insert(97);
$list->insert(98);
$list->insert(26);
foreach($list as $li)
{
    echo $li."\n";
}